import BasePageCtrl, { AnimType } from "./BasePageCtrl";
import MathUtils from "./MathUtil";
import { TravelEvent } from "./PeripheralSystemMgr";
import UiManager from "./UiManage";

import l from "./PlayerDataSys"
import s from "./PeripheralSystemDataMgr"
import c from "./AdManager"
import u from "./EngineUtil"
import p from "./MathUtil"
import d from "./BasePageCtrl"
import h from "./PeripheralSystemMgr"
import f from "./UiManage"
import g from "./TravelObstracleEventPage"
import n from "./AudioManager"


const { ccclass, property } = cc._decorator;

@ccclass
export default class TravelObstracleEventPageCtrl extends BasePageCtrl{
    ui = null;
    travelEventType = null;

   public _animType = AnimType.LEFT_TO_RIGHT;
   public _touchControl = false;
   public _hasPeneLock = true;
   public _hasBlack = true;
   public _hasTouchLock = false;
   public _hasBlackTouch = false;
   public _showWinSize = true;

    onLoad() {
        this.onUILoad();
        this._animType = AnimType.LEFT_TO_RIGHT;
        this._touchControl = false;
        this._hasPeneLock = true;
        this._hasBlack = true;
        this._hasTouchLock = false;
        this._hasBlackTouch = false;
        this._showWinSize = true;
        super.onLoad();
        this.addButtonListen();
    }

    start() { }

    onUILoad() {
        this.ui = this.node.addComponent(g);
    }

    _init(e?) {
        if (e) {
            var t = e.travelEventType;
            this.travelEventType = t;
            this.setShowUIByType();
            n.getInstance().playMusic("eventOut");
        }
    }

    setShowUIByType() {
        var e = this.travelEventType == TravelEvent.OBSTACLE_TIGER;
        this.ui.iconNode1.active = e;
        this.ui.iconNode2.active = !e;
        this.ui.tigerTipsLabel.active = e;
        this.ui.thiefTisLabel.active = !e;
        this.ui.deduction_des1.active = e;
        this.ui.deduction_des2.active = !e;
        this.ui.video_des1.active = e;
        this.ui.video_des2.active = !e;
        if (e) {
            this.ui.btn_deduction.y = -19;
            this.ui.btn_video.y = -19;
        } else {
            this.ui.btn_deduction.y = -81;
            this.ui.btn_video.y = -81;
        }
        var t = l.cash_balance;
        var a = MathUtils.accMul(t, 0.1);
        a = this.fomatFloat(a, 2);
        s.setReduceCash(a);
        var o = u.getCashBalance(a);
        this.ui.deductionCountLabel.getComponent(cc.Label).string = "-" + o + "元";
    }

    addButtonListen() {
        UiManager.addButtonListen(this.ui.btn_video, this.clickVideo, this);
        UiManager.addButtonListen(this.ui.btn_deduction, this.clickDeduction, this, 0, "cost_heart");
    }

    clickVideo() {
        var e = this;
        s.reportEncourageVideo();
        c.getInstance().playNormalVideoAd(function () {
            h.getVideoReward(e.travelEventType, 1, function () {
                e.hide();
            });
        }, function () { });
    }

    clickDeduction() {
        var e = this;
        h.getVideoReward(this.travelEventType, 0, function () {
            e.hide();
        });
    }

    clickClose() {
        this.hide();
        s.checkNextOutSideGuide();
        s.checkShowGameStartPage();
    }

    fomatFloat(e, t) {
        return Math.round(e * Math.pow(10, t)) / Math.pow(10, t);
    }
}
